<template>
    <div class="main">
        <banner></banner>
        <div class="h1">填写短信验证码</div>
        <div class="login-mobile pd20">
            <div class="input-box">
                <mt-field label="短信验证码" placeholder="请输入短信验证码" type="number" v-model="verify"></mt-field>
            </div>
            <div class="btn-box">
                <mt-button type="primary" size="large" @click.native="login()">确认登录</mt-button>
            </div>
        </div>
    </div>
</template>

<script>
import banner from '../components/banner.vue'
import { MessageBox } from 'mint-ui'
export default {
    name: 'index',

    data () {
        return {
            verify: ''
        }
    },

    mounted() {
        // this.logined()
    },
    
    methods: {
        login () {
            this.getHeaders()
            let ts = this
            let api = this.getApi('login')
            this.$ajax({
                method: 'POST',
                url: api,
                data: this.getFormData({verify: this.verify}),
                headers: this.headers,
            }).then(function(res){
                if(res.data.code == 1){
                    ts.$cookies.set('token', res.data.result.token, res.data.result.effective - 100)
                    ts.$cookies.set('refreshToken', res.data.result.refreshToken, 86400 * 29)
                    ts.$store.commit('setLogin', true)
                    ts.$router.go(0)
                } else {
                    MessageBox('提示', res.data.msg)
                    ts.$router.go(0)
                }
            }).catch(function(error){
                console.log(error)
            })
        }
    },
    components: {banner}
}
</script>